package com.lcn.controller;

import com.lcn.base.BaseInfoProperties;
import com.lcn.grace.result.GraceJSONResult;
import com.lcn.pojo.bo.CommentBO;
import com.lcn.pojo.vo.CommentVO;
import com.lcn.service.CommentService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/comment")
public class CommentController extends BaseInfoProperties {

    @Resource
    private CommentService commentService;

    /**
     * 评论朋友圈
     *
     * @param commentBO
     * @return
     */
    @PostMapping("/create")
    public GraceJSONResult create(@RequestBody @Valid CommentBO commentBO) {
        CommentVO commentVO = commentService.create(commentBO);
        return GraceJSONResult.ok(commentVO);
    }

    /**
     * 查询朋友圈评论
     *
     * @param friendCircleId
     * @return
     */
    @PostMapping("/query")
    public GraceJSONResult query(String friendCircleId) {
        if (StringUtils.isBlank(friendCircleId)) {
            return GraceJSONResult.error();
        }
        List<CommentVO> commentVOList = commentService.queryComment(friendCircleId);
        return GraceJSONResult.ok(commentVOList);
    }

}
